import request from '@/config/axios'
import { defHttp } from '@/utils/http/axios';
import { RequestEnum } from '@/enums/httpEnum';
import { ServicePrefixEnum } from '@/enums/commonEnum';
import type { AxiosRequestConfig } from 'axios';

const MODULAR = '/system/user';

export const Api = {
  GetUserPage: {
    url: `${ServicePrefixEnum.BASE}/${MODULAR}/page`,
    method: RequestEnum.GET,
  } as AxiosRequestConfig,
  GetAllUser: {
    url: `${ServicePrefixEnum.BASE}/${MODULAR}/all`,
    method: RequestEnum.GET,
  } as AxiosRequestConfig,
  GetUser: {
    url: `${ServicePrefixEnum.BASE}/${MODULAR}/get`,
    method: RequestEnum.GET,
  } as AxiosRequestConfig,
  CreateUser: {
    url: `${ServicePrefixEnum.BASE}/${MODULAR}/create`,
    method: RequestEnum.POST,
  } as AxiosRequestConfig,
  UpdateUser: {
    url: `${ServicePrefixEnum.BASE}/${MODULAR}/update`,
    method: RequestEnum.PUT,
  } as AxiosRequestConfig,
  DeleteUser: {
    url: `${ServicePrefixEnum.BASE}/${MODULAR}/delete`,
    method: RequestEnum.DELETE,
  } as AxiosRequestConfig,
  ResetUserPwd: {
    url: `${ServicePrefixEnum.BASE}/${MODULAR}/update-password`,
    method: RequestEnum.PUT,
  } as AxiosRequestConfig,
  UpdateUserStatus: {
    url: `${ServicePrefixEnum.BASE}/${MODULAR}/update-status`,
    method: RequestEnum.PUT,
  } as AxiosRequestConfig,
  GetSimpleUserList: {
    url: `${ServicePrefixEnum.BASE}/${MODULAR}/simple-list`,
    method: RequestEnum.GET,
  } as AxiosRequestConfig,
}

// 查询用户管理列表
export const getUserPage = (params) => {
  return defHttp.request({ ...Api.GetUserPage,params:params})
}

// 查询所有用户列表
export const getAllUser = () => {
  return defHttp.request({ ...Api.GetAllUser})
}

// 查询用户详情
export const getUser = (id: number) => {
  let params = {id}
  return defHttp.request({ ...Api.GetUserPage,params:params})
}

// 新增用户
export const createUser = (data: UserVO) => {
  return defHttp.request({ ...Api.CreateUser,params:data})
}

// 修改用户
export const updateUser = (data: UserVO) => {
  return defHttp.request({ ...Api.UpdateUser,params:data})
}

// 删除用户
export const deleteUser = (id: number) => {
  let params = {id}
  return defHttp.request({ ...Api.DeleteUser,params:params})
}

// 用户密码重置
export const resetUserPwd = (id: number, password: string) => {
  const params = {data:{id,password}}
  return defHttp.request({ ...Api.ResetUserPwd,params:params})
}

// 用户状态修改
export const updateUserStatus = (id: number, status: number) => {
  const params = {data:{id,status}}
  return defHttp.request({ ...Api.UpdateUserStatus,params:params})
}

// 获取用户精简信息列表
export const getSimpleUserList = (): Promise<UserVO[]> => {
  return defHttp.request({ ...Api.GetSimpleUserList})
}


export interface UserVO {
  id: number
  username: string
  nickname: string
  deptId: number
  postIds: string[]
  email: string
  mobile: string
  sex: number
  avatar: string
  loginIp: string
  status: number
  remark: string
  loginDate: Date
  createTime: Date
}

// 查询用户管理列表
// export const getUserPage = (params: PageParam) => {
//   return request.get({ url: '/system/user/page', params })
// }
//
// // 查询所有用户列表
// export const getAllUser = () => {
//   return request.get({ url: '/system/user/all' })
// }
//
// // 查询用户详情
// export const getUser = (id: number) => {
//   return request.get({ url: '/system/user/get?id=' + id })
// }
//
// // 新增用户
// export const createUser = (data: UserVO) => {
//   return request.post({ url: '/system/user/create', data })
// }
//
// // 修改用户
// export const updateUser = (data: UserVO) => {
//   return request.put({ url: '/system/user/update', data })
// }
//
// // 删除用户
// export const deleteUser = (id: number) => {
//   return request.delete({ url: '/system/user/delete?id=' + id })
// }

// 导出用户 todo
export const exportUser = (params) => {
  return request.download({ url: '/system/user/export', params })
}

// 下载用户导入模板 todo
export const importUserTemplate = () => {
  return request.download({ url: '/system/user/get-import-template' })
}

// 用户密码重置
// export const resetUserPwd = (id: number, password: string) => {
//   const data = {
//     id,
//     password
//   }
//   return request.put({ url: '/system/user/update-password', data: data })
// }
//
// // 用户状态修改
// export const updateUserStatus = (id: number, status: number) => {
//   const data = {
//     id,
//     status
//   }
//   return request.put({ url: '/system/user/update-status', data: data })
// }
//
// // 获取用户精简信息列表
// export const getSimpleUserList = (): Promise<UserVO[]> => {
//   return request.get({ url: '/system/user/simple-list' })
// }
